import javax.swing.JFrame;

import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartFrame;
import org.jfree.chart.JFreeChart;
import org.jfree.data.general.DefaultPieDataset;
/** GUI Test Frame 
 * 
 * @author AJ
 */
public class TestGUI {

	protected Shell shell;
	private Text textbox_URL;
	private Table table;
	private TableColumn tblclmnTestcol;
	private TableColumn tblclmnTestcol_1;

	/**
	 * Launch the application.
	 * @param args
	 */
	public static void main(String[] args) {
		try {
			TestGUI window = new TestGUI();
			window.open();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * Open the window.
	 */
	public void open() {
		Display display = Display.getDefault();
		createContents();
		shell.open();
		shell.layout();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
	}

	/**
	 * Create contents of the window.
	 */
	protected void createContents() {
		shell = new Shell();
		shell.setSize(584, 300);
		shell.setText("OpenDAP Client");
		
		textbox_URL = new Text(shell, SWT.BORDER);
		textbox_URL.setBounds(82, 10, 475, 21);
		
		Label lblDataUrl = new Label(shell, SWT.NONE);
		lblDataUrl.setBounds(10, 10, 55, 15);
		lblDataUrl.setText("Data URL:");
		
		Button btnGetData = new Button(shell, SWT.NONE);

		btnGetData.setBounds(482, 37, 75, 25);
		btnGetData.setText("Get Data");
		
		table = new Table(shell, SWT.BORDER | SWT.FULL_SELECTION);
		table.setBounds(10, 78, 228, 45);
		table.setHeaderVisible(true);
		table.setLinesVisible(true);
		final TableItem tItem = new TableItem(table, SWT.NONE);
		tItem.setText(textbox_URL.getText());
		
		tblclmnTestcol = new TableColumn(table, SWT.NONE);
		tblclmnTestcol.setWidth(100);
		tblclmnTestcol.setText("TestCol1");
		
		tblclmnTestcol_1 = new TableColumn(table, SWT.NONE);
		tblclmnTestcol_1.setWidth(100);
		tblclmnTestcol_1.setText("TestCol2");

		btnGetData.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				tItem.setText(textbox_URL.getText());
				DefaultPieDataset data = new DefaultPieDataset();
				data.setValue("category 1", 43.2);
				data.setValue("category 2", 27.9);
				data.setValue("category 3", 79.5);
				
				JFreeChart chart = ChartFactory.createPieChart(
						"Sample Pie Chart",
						data,
						true, // legend?
						true, // tooltips?
						false // URLs?
						);
				
				ChartFrame frame = new ChartFrame("First", chart);
				frame.pack();
				frame.setVisible(true);
				
				
				//Create another frame
				DataTableFrame frame2 = new DataTableFrame();
				frame2.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
				frame2.setVisible(true);
								
			}
		});
		

		
	}
}
